import {message,Modal} from 'antd';
import {WeaTools,WeaDialog} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;

export const fnJoinPara = (fn,para)=>{
	if(!fn || !para || typeof(fn) != "string") 
		return fn;
	let _st = fn.indexOf("(");
	let _ed = fn.lastIndexOf(")");
	if(_st == -1 || _ed == -1)
		return fn;
	let _stStr = fn.substring(0,_st);
	let _edStr = fn.substring(_ed);
	let _para = fn.substring(_st,_ed);
	_para += (_para == "(" ? "" : ",") + "'" + para + "'";
	return _stStr + _para + _edStr;
}

//查询客户   导出客户
export const crmExport = (module)=>{
    return WeaTools.callApi('/api/crm/customer/crmExport', 'GET', {}).then(data=>{
        window.location="/weaver/weaver.file.ExcelOut";          
    });
}

//发送邮件 ---查询客户里面的operate
export const opNewEmail =(email)=>{
    var url = "/email/new/MailInBox.jsp?opNewEmail=1&isInternal=0&to="+email;
    openFullWindowHaveBar(url); 
 }

 //新建流程
 export const opNewWF =(id)=>{
    var url = "/spa/workflow/index_mobx.html#/main/workflow/add?hasStruct=true&crmid="+id;
    openFullWindowHaveBar(url); 
 }

//发送邮件
export const sendMailBatch =(module)=>{
   return WeaTools.callApi('/api/crm/customer/getEmail', 'GET', {"customerIds":module}).then(data=>{
       var url = "/email/new/MailInBox.jsp?opNewEmail=1&isInternal=0&to="+data.datas;
       openFullWindowHaveBar(url); 
    });
}

//发送邮件
export const shareBatch =(module)=>{
    return WeaTools.callApi('/api/crm/customer/getEmail', 'GET', {"customerIds":module}).then(data=>{
        var url = "/email/new/MailInBox.jsp?opNewEmail=1&isInternal=0&to="+data.datas;
        openFullWindowHaveBar(url); 
     });
 }

 //批量删除
 export const deleteBatch = params =>{
    confirm({
        title: getLabel(15172,"系统提示"),
        content: getLabel(83600,"您确认要删除吗？"),
        okText:getLabel(33703,"确定"),
        cancelText:getLabel(201, "取消"),
        onOk() {
            return WeaTools.callApi('/api/crm/customer/crmDelete', 'GET', {"customerIds":params}).then(data=>{
                if(data.status == "success"){
                    //  window.store_e9_element.dispatch(SearchAction.doSearch());
                    window._crmTable.reLoad();
                }else{
                    message.error(getLabel(83437,"出现错误！") + data.msgcode);
                }
            });
        },
        onCancel() {},
    });
 }

 //升级
 export const doLevelUp =params =>{
    return WeaTools.callApi('/api/crm/customer/crmChangeStatus', 'GET', {"customerIds":params,operation:"up"}).then(data=>{
        if(data.status == "success"){
            return true;
        }else{
            message.error(getLabel(83437,"出现错误！") + data.msgcode);
        }
      });
 }
  //降级
  export const doLevelDown =params =>{
    return WeaTools.callApi('/api/crm/customer/crmChangeStatus', 'GET', {"customerIds":params,operation:"down"}).then(data=>{
        if(data.status == "success"){
            return true;
        }else{
            message.error(getLabel(83437,"出现错误！") + data.msgcode);
        }
      });
 }
 
 
